package eti.vilas.beans;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


public class Calculate {
	
	
	private List<Abast> abastList;
	Map<String, List<Abast>> abastMap = new HashMap<String, List<Abast>>();
	
	private double fator = 0.7;
	
	
	public Calculate(List<Abast> abastList) 
	{
		this.abastList = abastList;
		recalculaFator();
	}

	public void recalculaFator()
	{
		
		double rendAlcool = 0.0, rendGasol = 0.0;
		
		List<Abast> abastList2 = new ArrayList<Abast>();
		
		for (Abast abast : abastList) 
		{
		   if((abastList2 = abastMap.get(abast.getCombustivel())) != null)
		   {
		      abastList2.add(abast);
		   }
		   else
		   {
		      abastMap.put(abast.getCombustivel(), new ArrayList<Abast>());
		   }
		}
//		
//		System.out.println(abastMap);
//	       
//		
//		
//		
//		
//		System.out.println("RendAlcool: " + rendAlcool);
//		System.out.println("RendGasoli: " + rendGasol);
		
		
		
	}
	
	public boolean decidirCombustivel(double vrGasol, double vrAlcool)
	{
		return (vrAlcool / vrGasol) < fator;
	}
	
	public static String decidir() throws SQLException, ClassNotFoundException
	{
	   List<Abast> abastList  = DBConnection.getInstance().getAll();
	   Calculate calculate = new Calculate(abastList);
      return  calculate.decidirCombustivel(2.508, 0.7001 * 2.508) ? Combustivel.Etanol.toString() : Combustivel.Gasolina.toString();
      
	}
	
	public static void main(String[] args) throws Exception 
	{
	   System.out.println(decidir());
	}

}
